<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 父组件的数据改变了，那么传递给子组件的内容会同步改变 -->
      <!-- 子组件接受到的props的值是不能修改的 -->
      <h3>单向数据流 - <button @click="count++">btn</button></h3>
      <child :count="count"></child>
    </div>

    <script src="../../Vue.js"></script>
    <script>
      const Child = {
        props: {
          count: Number,
        },
        // 如果真的想改props的值，将props的值作为组件的data的默认值
        data() {
          return {
            num: this.count,
          };
        },
        // 计算还可以依赖于props的值
        computed: {
          doubleCount() {
            return this.count * 2;
          },
        },
        template: `
          <div>child组件 - {{ num }} - {{ doubleCount }} - <button @click="num++">btn2</button></div>
        `,
        mounted() {
          console.log(this.count);
        },
      };

      new Vue({
        el: "#app",
        data: {
          count: 10,
        },
        components: {
          Child,
        },
      });
    </script>
  </body>
</html>
